package com.damai.core;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

import static com.damai.constant.Constant.DEFAULT_PREFIX_DISTINCTION_NAME;
import static com.damai.constant.Constant.PREFIX_DISTINCTION_NAME;

//ApplicationContextInitializer是Spring框架中的一个接口,用于在ApplicationContext实例化后但在其刷新之前对其进行初始化;
//ConfigurableApplicationContext是Spring中一个可配置的应用程序上下文接口,它扩展了ApplicationContext并提供了更多的配置选项;
public class SpringUtil implements ApplicationContextInitializer<ConfigurableApplicationContext> {

    private static ConfigurableApplicationContext configurableApplicationContext;

    //从环境变量中获取属性名对应的值,如果没有,则返回默认值"damai"
    public static String getPrefixDistinctionName(){
        return configurableApplicationContext.getEnvironment().getProperty(PREFIX_DISTINCTION_NAME,  DEFAULT_PREFIX_DISTINCTION_NAME);
    }

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        configurableApplicationContext = applicationContext;
    }
}
